public class MyBlockedQueue {
    int[] nums = new int[10];
    int head = 0;
    int tail = 0;
    int size = 0;
    Object locker = new Object();

    public static void main(String[] args) throws InterruptedException {
        MyBlockedQueue myBlockedQueue = new MyBlockedQueue();
        myBlockedQueue.put(1);
        myBlockedQueue.put(5);
    }


    public void put(int val) throws InterruptedException {
        synchronized (locker) {
            while (size == nums.length) {
                locker.wait();
            }
            nums[tail%nums.length] = val;
            tail++;
            size++;
            locker.notify();
        }
    }

    public int take() throws InterruptedException {
        synchronized (locker) {
            while (size == 0) {
                locker.wait();
            }
            int ret = nums[head%nums.length];
            head++;
            size--;
            locker.notify();
            return ret;
        }
    }
}
